<template>
	<view class="container">
		<view class="yong">
			<image class="hu" src="/static/head_icon.png"></image>
		</view>
		<view class="content">
			<uni-forms ref="form" :model="user" :rules="myrules">
				<uni-forms-item label="用户名" name="username">
					<uni-easyinput v-model="user.username" placeholder="请输入用户名" @iconClick="iconClick" />
				</uni-forms-item>
				<uni-forms-item label="密码" name="password">
					<uni-easyinput v-model="user.password" placeholder="请输入密码" prefixIcon="locked" type="password" />
				</uni-forms-item>
				<uni-forms-item>
					<button type="primary" @click="login">登录</button>
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					username: '',
					password: '',
					icon: '/static/head_icon.png'
				},
				myrules: {
					username: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}, {
							minLength: 3,
							maxLength: 5,
							errorMessage: '长度不符合要求'

						}]
					},
					password: {}
				}

			}
		},
		methods: {
			login() {
				let result = this.$refs.form.validate()
				if (this.username === this.username && this.password === this.password) {
					console.log('登录成功');
				}
			}
		}
	}
</script>
<style>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-top: 20px;
	}

	.yong {
		margin-bottom: 40rpx;
	}

	.hu {
		width: 200rpx;
		height: 200rpx;
		border-radius: 50%;
	}

	.form-wrapper {
		width: 80%;
	}

	uni-forms-item {
		margin-bottom: 20px;
	}

	button {
		background: linear-gradient(to right, #0167ff, #418aff);
	}
</style>